package com.example.teatea.dao;

import com.example.teatea.project.Member;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class AddMember {
    public int addMember(Member member){
        int r = 0;
        Connection connection = null;
        ResultSet resultSet = null;
        Properties info = new Properties();
        try {
            info.load(new FileInputStream("src/main/resources/com/example/teatea/sql.properties"));
            String user = info.getProperty("user");
            String password = info.getProperty("password");
            String Driver = info.getProperty("Driver");
            String url = info.getProperty("url");
            Class.forName(Driver);
            connection = DriverManager.getConnection(url,user,password);
            String sql = "insert into members(mName,mSex,mBirthday,mPhone,mTime)values(?,?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,member.getmName());
            preparedStatement.setString(2,member.getmSex());
            preparedStatement.setString(3,member.getmBirthday());
            preparedStatement.setString(4,member.getmPhone());
            preparedStatement.setString(5,member.getmTime());
            r = preparedStatement.executeUpdate();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return r;
    }
}
